package com.mydubbo.proxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CglibProxyFactory extends BaseProxyFactory {
	
	@Override
	public Object getProxy(Class<?> clazz) {
		Enhancer enhancer = new Enhancer();
		enhancer.setCallback(new MethodInterceptor() {
			@Override
			public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
				Class<?> clazz = obj.getClass().getInterfaces()[0];
				return invoker.invoke(clazz, method, args);
			}
		});
		enhancer.setInterfaces(new Class[]{clazz});
		Object proxy = enhancer.create();
		return proxy;
	}

}
